﻿namespace NMortgage.UI.Tests.ViewModels
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Caliburn.Micro;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using NMortgage.UI.Events;
    using NMortgage.UI.Model;
    using NMortgage.UI.Properties;
    using NMortgage.UI.ViewModels;

    [TestClass]
    public class LoanProfileViewModelTest : TestBase<LoanProfileViewModel>
    {
        #region Methods

        [TestMethod]
        public void AvailableFrequencies()
        {
            var expected = Enum.GetValues(typeof(PaymentFrequency));
            var actual = Subject.AvailableFrequencies;
            CollectionAssert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void Title_Should_Be_From_Resources()
        {
            var expected = Resources.LoadProfileTitle;
            var actual = Subject.Title;
            Assert.AreEqual(expected, actual);
        }

        private void SetFixedInterestRate(double interestRate, int years )
        {
            //todo Can this API be simpler?
            var parameter = new InterestParameter(DistributionType.FixedRate);
            parameter.Years = years;
            parameter.Months = 0;
            var rate = parameter.Distribution as FixedRate;
            rate.Rate = interestRate;
            Subject.InterestRates.Handle(new ProfileItemAdded(parameter));
        }

        private void SetupForBiweeklyPayment()
        {
            SetupLoanProfile();
            Subject.SelectedPaymentFrequency = PaymentFrequency.Biweekly;
        }

        private void SetupForMonthlyPayment()
        {
            SetupLoanProfile();
            Subject.SelectedPaymentFrequency = PaymentFrequency.Monthly;
        }

        private void SetupLoanProfile()
        {
            SetFixedInterestRate(5d,5);
            Subject.LoanAmount = 50000;
        }

        #endregion Methods
    }
}